package com.chlitina.store.modules.cash.model;

import com.chlitina.store.modules.cash.entity.StoreCardProduct;
import com.chlitina.store.modules.cash.model.recharge.CardProductRecharge;

public class ProductCardPayment extends CardPayment{
	public ProductCardPayment(StoreCardProduct card, long id){
		super(card,id);
		setNewCard(getCard().getId()==null);
		setRealMoney(card.getMoney());
		setCurrentMoney(card.getMoney());
	}
	
	
	
	public StoreCardProduct getCard() {
		return (StoreCardProduct) card;
	}
	
	public boolean addMoney(float addValue){
		float temp=money+addValue;
		if(temp> getCard().getMoney()){
			return false;
		}
		money+=addValue;
		return true;
	}
	
	public boolean minusMoney(float minusValue){
		if(minusValue>money){
			return false;
		}
		money-=minusValue;
		return true;
	}

 
	public void payMoney() {
		super.payMoney(getRealCost());
		setRealCost(0);
	}



	public void recharge(CardProductRecharge recharge) {
		System.err.println("-----------");
		System.err.println("Recharge:" + recharge.toString());
		System.err.println("Before Recharge:" + toString());
		float rechargeMoney = recharge.getRechargeMoney();
		setRechargeMoney(getRechargeMoney() + rechargeMoney);
		setCurrentMoney(getCurrentMoney() + rechargeMoney);
		System.err.println("End Recharge:" + toString());
	}
	
}
